//
//  NewFeatureView.m
//  新特性
//
//  Created by 吴俊杰 on 2016/11/17.
//  Copyright © 2016年 吴俊杰. All rights reserved.
//

#import "JPNewFeatureView.h"
#import "JPNewFeatureSV.h"
#import <Masonry.h>

@interface JPNewFeatureView () <UIScrollViewDelegate>

@property (nonatomic, weak)UIPageControl *pageControl;

@end

@implementation JPNewFeatureView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupUI];
    }
    return self;
}

/**
 初始化界面
 */
- (void)setupUI{
    // 创建新特性界面
    JPNewFeatureSV *newFeatureView = [[JPNewFeatureSV alloc] initWithFrame:self.bounds];
    [self addSubview:newFeatureView];
    newFeatureView.delegate = self;
    
    // 创建分页指示器
    UIPageControl *pageControl = [[UIPageControl alloc] initWithFrame:CGRectZero];
    [self insertSubview:pageControl aboveSubview:newFeatureView];
    self.pageControl = pageControl;
    // 设置分页指示器
    pageControl.numberOfPages = 4;
    pageControl.currentPage = 0;
    pageControl.pageIndicatorTintColor = [UIColor yellowColor];
    pageControl.currentPageIndicatorTintColor = [UIColor redColor];
    
    [pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self);
        make.bottom.equalTo(self).offset(-50);
    }];
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    int page = scrollView.contentOffset.x / self.bounds.size.width + 0.5;
    self.pageControl.currentPage = page;
    if (page == 4) {
        [self removeFromSuperview];
    }
}


@end
